﻿//双击事件
var CustomDbClick = function () {
    
}
//自定义新增
var fnCustomAdd = function () {
    //    var list = this.mDataTable.getRecordSet()._records;
    //    var elist = [];
    //    for (var i = 0; i < list.length; i++) {
    //        if (list[i]._oData["iSun_Selected"] == true) {
    //            elist.push(list[i]._oData["MajorStudentId"]);
    //        }
    //    }
    //    ids = elist;
    //    if (ids.length > 0) {
    //        document.getElementById("EditUIWindow").src = "../Crm/MajorStudentGroup.aspx?r=" + Math.random() + "&entity=CrmMajorStudent_G";
    //        document.getElementById("yui-gen9-button").style.display = "block";
    //        YAHOO.example.container.dialog1.show();
    //        /*document.getElementById("EditUIWindow").src = "../Extend/AutoEditUI.aspx?r=" + Math.random() + "&entity=CrmMajorStudent_G";
    //        document.getElementById("yui-gen9-button").style.display = "block";
    //        YAHOO.example.container.dialog1.show();*/
    //    }
    //    else {
    //        alert('您没有选中任何项');
    //    }
}
//自定义修改学员基本信息方法fnEditStudent
var fnCustomEdit = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var elist = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            elist.push(list[i]._oData["MajorStudentId"]);
        }
    }
    ids = elist;
    if (ids.length == 0) {
        alert('请选择学员');
        return;
    } else if (ids.length >= 2) {
        alert('您选择了多行记录,修改请单行选择!');
        return;
    } else {
        if (Y.util.Dom.getViewportHeight() < 401) {
            //alert(Y.util.Dom.getViewportHeight());
            SetMaxDWH(YAHOO.example.container.dialog1);
        }
        var recordID = myDataTable.getSelectedRows()[0];
        record = myDataTable.getRecord(recordID);
        document.getElementById("EditUIWindow").src = "http://" + this.location.host + "/Extend/AutoEditUI.aspx?r=" + Math.random() + "&entity=" + const_EditEntity + "&id=" + record.getData("MajorStudentId");
        document.getElementById("yui-gen9-button").style.display = "block";
        SetDWH(500, 450, YAHOO.example.container.dialog1);
        YAHOO.example.container.dialog1.show();
    }
}
//自定义删除方法
var fnCustomDeleteData = function () {
    YAHOO.example.container.dialog3.hide();
}
//自定义查询
var fnCustomQueryRe = function (condition) {
    try {
        if (fkey != '00000000-0000-0000-0000-000000000000')
            const_CustomCondition = condition + " and (ProductLayoutID='" + fkey + "')";
        else
            const_CustomCondition = condition;
    } catch (e) {
        const_CustomCondition = vConditions;
    }
    RefreshData();
}
//自定义刷新
var fnRefreshData = function () {
    if (fkey != '00000000-0000-0000-0000-000000000000')
        const_CustomCondition = " (ProductLayoutID='" + fkey + "')";
    else
        const_CustomCondition = "00000000-0000-0000-0000-000000000000";
    ReLoadData();
}




//新增学员
var fnAddStudent = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        window.parent.$("#tabs").tabs('close', '新增大课学员');
        var pagetitle = "新增大课学员";
        parent.addTabs(pagetitle, '../Crm/Deliver/AddDeliverMajor.aspx?r=' + Math.random() + '&flag=0&type=0&entity=CrmDeliverMajor&key=' + fkey + '&title=' + encodeURI(pagetitle));
        parent.NeedRefreshPage = this;
    }
}
//学员分团
var fnAddPartion = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        window.parent.$("#tabs").tabs('close', '学员分团');
        var pagetitle = "学员分团";
        parent.addTabs(pagetitle, '../Crm/StudentSign.aspx?r=' + Math.random() + '&title=' + encodeURI(pagetitle) + '&id=' + fkey);
        parent.NeedRefreshPage = this;
    }
}
//设置团长
var fnSetManager = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var managerId; //团长ID
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            managerId = list[i]._oData["MajorStudentId"];
            break;
        }
    }
    if (managerId == undefined) {
        alert('请选择学员');
        return;
    }
    var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx";
    YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=Update&entity=V_CrmMajorStudent&id=" + managerId, callback);
}
//设置辅导员
var fnSetAssistance = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        document.getElementById("EditUIWindow").src = "../Crm/StudentSetAssistance.aspx?r=" + Math.random() + "&id=" + fkey;
        document.getElementById("yui-gen9-button").style.display = "block";
        YAHOO.example.container.dialog1.show();
    }
}
//签到
var fnSignIn = function () {
    var list = this.mDataTable.getRecordSet()._records;
    var StudentId = []; //学员ID
    var MajorId = []; //大课ID
    var IsTrain = []; //是否复训
    var IsDecision = []; //是否决策人
    var CustomerId = []; //客户ID
    var OrderProductId = []; //订单产品ID
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            MajorId.push(list[i]._oData["ID"]);
            StudentId.push(list[i]._oData["MajorStudentId"]);
            IsTrain.push(list[i]._oData["IsTrain"]);
            IsDecision.push(list[i]._oData["IsDecision"]);
            CustomerId.push(list[i]._oData["CustomerId"]);
            OrderProductId.push(list[i]._oData["OrderProductID"]);
        }
    }
    ids = StudentId;
    if (ids.length == 0) {
        alert("您没有选中任何学员,无法签到!");
        return;
    }
    if (confirm("是否确定签到?")) {
        var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx";
        for (var i = 0; i < ids.length; i++) {
            var vStr = ids[i] + "," + MajorId[i] + "," + IsTrain[i] + "," + IsDecision[i] + "," + CustomerId[i] + "," + OrderProductId[i];
            YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=Update&entity=V_CrmMajorStudent1&id=" + vStr, callback1);
        }
    }
}
//取消签到
var fnResetSignIn = function () {
    var MajorId = []; //大课ID
    var OrderProductId = "";
    var StudentId = "";
    var list = this.mDataTable.getRecordSet()._records;
    for (var i = 0; i < list.length; i++) {
        if (list[i]._oData["iSun_Selected"] == true) {
            MajorId.push(list[i]._oData["ID"]);
            OrderProductId = list[i]._oData["OrderProductID"];
            StudentId = list[i]._oData["MajorStudentId"];
        }
    }
    ids = MajorId;
    if (ids.length == 0) {
        alert("您没有选中任何学员,无法取消签到!");
        return;
    } else if (ids.length > 1) {
        alert("只能勾选其中一条记录!");
        return;
    } else {
        if (confirm("是否确定取消签到?")) {
            var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx";
            YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&action=Update&entity=CrmMajorStudentResetSignIn&StudentId=" + StudentId + "&OrderProductId=" + OrderProductId + "&ProductLayoutId=" + fkey + "", callback2);
        }
    }
}
//改期
var fnSetIsGaiQi = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    if (recordID != null && recordID.length != 1) {
        record = myDataTable.getRecord(recordID);
        var sId = record._oData["MajorStudentId"];
        if (confirm("是否确定将该学员改期?")) {
            SetIsGaiQi(sId);
        }
    }
}
var SetIsGaiQi = function (studentId) {
    var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx?r=" + Math.random() + "&id=" + studentId + "&action=update&entity=CrmMajorStudentExp5";
    YAHOO.util.Connect.asyncRequest('GET', url,
        { success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    alert("设置学员改期成功!");
                    ReLoadData();
                } else {
                    alert(str);
                }
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
        });
}

var responseSuccess = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert('设置成功');
            ReLoadData();
        }
        else {
            alert('设置失败');
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback = {
    success: responseSuccess,
    failure: responseFailure
};
var responseSuccess1 = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert('签到成功');
            ReLoadData();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure1 = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback1 = {
    success: responseSuccess1,
    failure: responseFailure1
};
var responseSuccess2 = function (res) {
    try {
        var str = res.responseText;
        if (str == "1") {
            alert('设置成功');
            ReLoadData();
        }
        else {
            alert(str);
        }
    } catch (e) {
    }
    finally {
    }
};
var responseFailure2 = function (error) {
    alert("数据错误：" + error.statusText);
}
var callback2 = {
    success: responseSuccess2,
    failure: responseFailure2
};
var showMessage = function () {
    alert('签到成功');
}



//格式化列
var formatDecision = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatTrain = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatIsSignIn = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatGaiQi = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0") {
        elCell.innerHTML = "否";
    } else if (sData == "1") {
        elCell.innerHTML = "是";
    } else {
        elCell.innerHTML = "";
    }
}
var formatSignIn = function (elCell, oRecord, oColumn, sData) {
    if (sData == "0001-01-01 " || sData == "1900-01-01 ") {
        elCell.innerHTML = "";
    } else {
        elCell.innerHTML = sData;
    }
}


//复制
var fnCopy = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        var list = this.mDataTable.getRecordSet()._records;
        var elist = [], CustomerIdList = [];
        for (var i = 0; i < list.length; i++) {
            if (list[i]._oData["iSun_Selected"] == true) {
                elist.push(list[i]._oData["MajorStudentId"]);
                CustomerIdList.push(list[i]._oData["CustomerId"]);
            }
        }
        ids = elist;
        if (ids.length == 0) {
            alert('请选择学员');
            return;
        } else if (ids.length > 1) {
            var id = CustomerIdList[0];
            for (var j = 0; j < CustomerIdList.length; j++) {
                if (CustomerIdList[j] != id) {
                    alert("多选复制时所选择的学员必须为同一个公司!");
                    return;
                }
            }
        }
        var condition = "";
        document.getElementById("EditUIWindow").src = "http://" + this.location.host + "/EditWidows/ChooseList.aspx?r=" + Math.random() + "&entity=CrmProductLayout&kid=ID&kname=CourseLayoutName&condition=" + decodeURI(condition);
        SetDWH(500, 450, YAHOO.example.container.dialog1);
        YAHOO.example.container.dialog1.show();
    }
}
//保存复制操作
var SaveCopy = function (ProductLayoutId) {
    if (ProductLayoutId == "") {
        alert("请选择课程!");
        return;
    } else {
        //alert(ids);
        //alert(ProductLayoutId);
        var url = "http://" + this.location.host + "/Extend/AjaxData/DataProcessin.aspx?r=" + Math.random() + "&pid=" + ProductLayoutId + "&sid=" + ids + "&action=update&entity=CrmDeliverMajorCopy";
        YAHOO.util.Connect.asyncRequest('GET', url,
        { success: function (res) {
            try {
                var str = res.responseText;
                if (str == "1") {
                    alert("复制学员成功!");
                    //ReLoadData();
                } else {
                    alert(str);
                }
            }
            catch (e) {
            }
            finally {
            }
        }, failure: function () { }
        });
        return 1;
    }
}
//谈单导出
var fnCustoerReport = function () {
    if (fkey == "" || fkey == "00000000-0000-0000-0000-000000000000") {
        alert("请选择左侧课程期数菜单!");
    } else {
        window.parent.$("#tabs").tabs('close', '报表/导出');
        var const_CustomCondition = " ProductLayoutID='" + fkey + "'";
        parent.addTabs("报表/导出", "/Extend/AutoLoadReportView.aspx?entity=V_CrmDeliverMajorStudent_Customer&customCondition=" + const_CustomCondition);
    }
}
var fnCustomReport = function () {
    parent.addTabs("课程排位报表", ("Extend/ReportView.aspx?entity=V_CrmDeliverMajorStudent&order=OrderofDeptName&condition=" + const_Condition + "&customCondition=" + const_CustomCondition));
}